(function () {

  /**
   * mode 1 新增, 2 编辑
   */
  function getFormBody(mode = '1')
  {
    return [
      {
        "type": "text",
        "size": "lg",
        "name": "name",
        "label": "视频名称",
        "required": true
      },
      {
        "label": "视频分类",
        "type": "select",
        "size": "lg",
        "name": "video_category_id",
        "searchable": true,
        "clearable": true,
        "required": true,
        "source": "get:/b/vc/options?state=1",
      },
      {
        "type": "file",
        "size": "lg",
        "name": "video",
        "label": "视频",
        "btnLabel": "视频上传",
        "useChunk": false,
        "accept": ".mp4,.avi,.rmbv,.rm,.flv,.3gp",
        "required": true,
        "receiver": "post:/b/site/upload?type=video",
      },
    ];
  }

  return {
    "type": "page",
    "initApi": "/b/permits/init",
    "title": "课程分类",
    "toolbar": [
      {
        "type": "button",
        "actionType": "drawer",
        "label": "新增",
        // "visibleOn": "isInArray(this.front_end, 'scale_category_save')",
        "icon": "fa fa-plus pull-left",
        "primary": true,
        "drawer": {
          "title": "新增",
          "closeOnOutside": true,
          "closeOnEsc": true,
          "resizable": true,
          "position": "right",
          "size": "lg",
          "body": {
            "type": "form",
            // "debug": true,
            "persistData": "course_insert",
            "clearPersistDataAfterSubmit": true,
            "name": "新增表单",
            "api": "post:/b/video/save",
            "controls": getFormBody(),
          }
        }
      }
    ],
    "body": {
      "type": "crud",
      "className": "break-all",
      "hideQuickSaveBtn": true,
      "api": "get:/b/video/index",
      "quickSaveApi": "post:/b/video/batch",
      "quickSaveItemApi": "post:/b/video/item?id=$id",
      // "itemCheckableOn": "this.is_super !== 1 && this.leader_count === 0",
      "perPage": 10,
      "keepItemSelectionOnPageChange": true,
      "maxKeepItemSelectionLength": 20,
      "pageField": "page",
      "perPageField": "page_size",
      "labelTpl": "${name}",
      "syncLocation": false,
      "filter": {
        "title": "条件搜索",
        "submitText": "搜索",
        "controls": [
          {
            "label": "视频名称：",
            "type": "text",
            "size": "sm",
            "name": "name",
            "placeholder": "请输入"
          },
        ],
        "actions": [
          {
            "type": "button",
            "actionType": "clear",
            "label": "重置"
          },
          {
            "type": "button",
            "actionType": "submit",
            "label": "搜索",
            "level": "primary",
          }
        ]
      },
      "bulkActions": [
        // {
        //   "label": "批量删除",
        //   "visibleOn": "isInArray(this.front_end, 'admin_list_delete')",
        //   "level": "danger",
        //   "actionType": "ajax",
        //   "api": "post:/b/admin/del/${ids|raw}",
        //   "confirmText": "确定要批量删除?"
        // }
      ],
      "filterTogglable": true,
      "headerToolbar": [
        "filter-toggler",
        "bulkActions",
        {
          "type": "columns-toggler",
          "align": "right"
        },
        {
          "type": "pagination",
          "align": "right"
        }
      ],
      "footerToolbar": [
        "statistics",
        "switch-per-page",
        "pagination"
      ],
      "columns": [
        {
          "name": "id",
          "label": "ID",
          "hidden": true,
          "sortable": true,
          "type": "text",
          "toggled": true
        },
        {
          "name": "name",
          "label": "视频名称",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
          // "quickEdit": {
          //   "type": "text",
          //   "saveImmediately": true
          // },
          // "quickEditEnabledOn": "isInArray(this.front_end, 'admin_list_update')",
        },
        {
          "name": "category_name",
          "label": "视频分类",
          "sortable": false,
          "searchable": false,
          "type": "text",
          "toggled": true,
        },
        // {
        //   "name": "state",
        //   "type": "switch",
        //   "width": 50,
        //   "label": "禁用/启用",
        //   "trueValue": 1,
        //   "falseValue": 2,
        //   "quickEdit": {
        //     "type": "switch",
        //     "trueValue": 1,
        //     "falseValue": 2,
        //     "mode": "inline",
        //     "saveImmediately": true,
        //     // "disabledOn": "!isInArray(this.front_end, 'admin_list_update') || this.is_super === 1"
        //   }
        // },
        {
          "name": "creator",
          "label": "创建人",
          "type": "text",
          "sortable": false,
          "toggled": true
        },
        {
          "name": "created_at",
          "label": "创建时间",
          "type": "text",
          "sortable": false,
          "toggled": true
        },
        {
          "type": "operation",
          "label": "操作",
          "buttons": [
            {
              "type": "button",
              "label": "编辑",
              // "visibleOn": "isInArray(this.front_end, 'scale_category_update')",
              "level": "primary",
              "actionType": "drawer",
              "drawer": {
                "position": "right",
                "size": "lg",
                "title": "编辑",
                "closeOnOutside": true,
                "closeOnEsc": true,
                "resizable": true,
                "body": {
                  "type": "form",
                  // "debug": true,
                  "name": "编辑",
                  "api": "post:/b/video/update?id=$id",
                  "controls": getFormBody('2')
                }
              }
            }
          ],
          "toggled": true
        }
      ]
    }
  };
})();